package com.sgb.net.core;

import com.sgb.net.BuildConfig;

import java.util.LinkedList;

import okhttp3.Interceptor;

/**
 * @author: 杨畔
 * @date: 2021/2/20 09:32
 * @Description: 客户端配置
 */
public class NetConfig {
    //接口地址，默认取gradle中设置的
    static String mBaseUrl = BuildConfig.BASE_URL;
    //超时时间，默认10s
    static long mTimeOut = 10L;
    //拦截器集合
    static LinkedList<Interceptor> mInterceptors = new LinkedList<>();

    private static class Single {
        private static final NetConfig instance = new NetConfig();
    }

    public static NetConfig config() {
        return Single.instance;
    }

    /**
     * 设置接口地址
     *
     * @param baseUrl 接口地址
     */
    public NetConfig baseUrl(String baseUrl) {
        mBaseUrl = baseUrl;
        return this;
    }


    /**
     * 设置超时时间
     *
     * @param time 超时时间，单位s
     */
    public NetConfig timeOut(long time) {
        mTimeOut = time;
        return this;
    }

    /**
     * 添加拦截器
     *
     * @param interceptor 拦截器
     */
    public NetConfig addInterceptor(Interceptor interceptor) {
        if (interceptor == null) {
            throw new NullPointerException("interceptor is null");
        }
        mInterceptors.add(interceptor);
        return this;
    }
}
